package com.lk.api.own;

import android.app.Activity;
import android.app.Service;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.lk.api.own.LocalService.LocalBinder;
import com.lk.api.R;

public class LocalServiceTestActivity extends Activity {
	private Button mLocaiBinderStart, mLocaiBinderStop;
	static final String TAG = "LocalServiceTestActivity";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.locaiservicetestactivity);

		mLocaiBinderStart = (Button) findViewById(R.id.StartlocaiBinder);
		mLocaiBinderStop = (Button) findViewById(R.id.StoplocaiBinder);
		mLocaiBinderStart.setOnClickListener(mLocalBinderStartClickListener);
		mLocaiBinderStop.setOnClickListener(mLocalBinderStopClickListener);
	}
	public ServiceConnection conn = new ServiceConnection() {

		@Override
		public void onServiceDisconnected(ComponentName name) {
			// TODO Auto-generated method stub
			Log.d(TAG, "Service Disconnected");

		}

		@Override
		public void onServiceConnected(ComponentName name, IBinder service) {
			// TODO Auto-generated method stub
			Log.d(TAG, "Service Connected");
			LocalService localService = ((LocalBinder) service)
					.getLocalService();
			localService.sayHelloWorld();

		}
	};

	public OnClickListener mLocalBinderStartClickListener = new OnClickListener() {
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Log.d(TAG, "Button Start Service");
			Intent intent = new Intent(LocalServiceTestActivity.this,
					LocalService.class);
			bindService(intent, conn, Service.BIND_AUTO_CREATE);

		}
	};

	public OnClickListener mLocalBinderStopClickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Log.d(TAG, "Button Stop Service");
			unbindService(conn);

		}
	};

}
